/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBFunction;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class fAllPOIs {
	public static String process(String currentPhoneNumber)
			throws JSONException {
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();

		String sql = "SELECT user.PhoneNumber,poi.POIid, poi.Title, user.FirstName,user.LastName,poi.Latitude,poi.Longitude,poi.Description, poi.MarkedTime,poi.IsHidden from buddytracking.user, buddytracking.poi where GroupId = ( select GroupId from buddytracking.user where User.PhoneNumber='"
				+ currentPhoneNumber
				+ "') and poi.UserId = user.UserId  and GroupId != \"0\"";
		ResultSet resultSet = DB.connectDB.ExecuteQuery(sql);

		try {
			while (resultSet.next()) {
				String markerName = resultSet.getString("FirstName") + " "
						+ resultSet.getString("LastName");
				object.put("markerPhoneNumber", resultSet.getString("PhoneNumber"));
				object.put("POIid", resultSet.getString("POIid"));
				object.put("POITitle", resultSet.getString("Title"));
				object.put("markerName", markerName);
				object.put("lat", resultSet.getString("Latitude"));
				object.put("log", resultSet.getString("Longitude"));
				object.put("description", resultSet.getString("Description"));
				object.put("markedTime", resultSet.getString("MarkedTime"));
				object.put("isHidden", resultSet.getString("IsHidden"));
				array.put(object.toString());
			}
		} catch (SQLException ex) {
		}
		return array.toString();
	}
}
